<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <script type="text/javascript" src="../../js/commonCss.js"></script>
    <link rel="stylesheet" type="text/css" href="../../styles/common.css" />
    <script src="../../js/jquery-3.2.1.min.js"></script>
    <script src="../../js/jquery.formHelp.js"></script>
</head>
<body>
<form class="definewidth m20" id="subform">
    <p>项目信息概况：</p>
    <table class="table table-bordered table-hover m10">
        <tr class="hidden">
            <td width="10%" class="tableleft">项目id</td>
            <td><input type="text" name="projectId" id="projectId" value="" disabled/></td>
        </tr>
        <tr class="hidden">
            <td width="10%" class="tableleft">是否有效</td>
            <td><input type="text" name="isValid" id="isValid" value="true" disabled/></td>
        </tr>
    <tr>
        <td width="10%" class="tableleft">项目编号</td>
        <td>
            <input type="text" name="projectCode" class="form-control input-sm w300" id="projectCode" disabled/>
        </td>
    </tr>
    <tr>
        <td class="tableleft">原项目编号</td>
        <td><input type="text" name="oldProjectCode" class="form-control input-sm w300" id="oldProjectCode" disabled/></td>
    </tr>
    <tr>
        <td class="tableleft">项目名称</td>
        <td><input type="text" name="projectName" class="form-control input-sm w300" id="projectName" disabled/></td>
    </tr>
    <tr>
        <td class="tableleft">立项日期</td>
        <td><input type="text" name="establishDate" class="form-control input-sm w300" id="establishDate" disabled/></td>
    </tr>
    <tr>
        <td class="tableleft">项目类型</td>
        <td>
            <select name="projectType" id="projectType" class="form-control input-sm w300" disabled>
            </select>
        </td>
    </tr>
    <tr>
        <td class="tableleft">项目经理</td>
        <td>
            <select name="pmOrganization" id="pmOrganization" class="form-control input-sm w140 dib mr15" disabled>
            </select>
            <select name="projectManager" id="projectManager" class="form-control input-sm w140 dib" disabled>
            </select>
        </td>
    </tr>
    <tr>
        <td class="tableleft">销售负责人</td>
        <td>
            <select name="salerOrganization" id="salerOrganization" class="form-control input-sm w140 dib mr15" disabled>
            </select>
            <select name="saler" id="saler" class="form-control input-sm w140 dib" disabled>
            </select>
        </td>
    </tr>
    <tr>
        <td class="tableleft">销售分类</td>
        <td>
            <select name="saleType" id="saleType" class="form-control input-sm w300" disabled>
            </select>
        </td>
    </tr>
    <tr>
        <td class="tableleft">项目包</td>
        <td><input type="text" name="projectPackage" id="projectPackage" class="form-control input-sm w300" disabled/></td>
    </tr>
    <tr>
        <td class="tableleft">关联项目</td>
        <td>
            <select name="relatedProject" id="relatedProject" class="form-control input-sm w300" disabled>
            </select>
        </td>
    </tr>
    <tr>
        <td class="tableleft">项目状态</td>
        <td>
            <select name="projectStatus" id="projectStatus" class="form-control input-sm w300" disabled>
            </select>
        </td>
    </tr>
</table>
    <p>合同信息概况：</p>
    <table class="table table-bordered table-hover m10">
        <tr>
            <td width="10%" class="tableleft">签订日期</td>
            <td><input type="text" name="singDate" id="singDate" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">合同编号</td>
            <td><input type="text" name="contractNo" id="contractNo" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">合同名称</td>
            <td><input type="text" name="contractName" id="contractName" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">合同类型</td>
            <td>
                <select name="contractType" id="contractType" class="form-control input-sm w300" disabled>
                </select>
            </td>
        </tr>
        <tr>
            <td class="tableleft">服务周期</td>
            <td><input type="text" name="serviceCycle" id="serviceCycle" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">维保期</td>
            <td><input type="text" name="maintenancePeriod" id="maintenancePeriod" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">客户名称</td>
            <td><input type="text" name="customerName" id="customerName" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">地址</td>
            <td><input type="text" name="customerAddress" id="customerAddress" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">负责人</td>
            <td><input type="text" name="customerInCharge" id="customerInCharge" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">产品总金额/元</td>
            <td><input type="text" name="totalProductAmount" id="totalProductAmount" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">服务总金额/元</td>
            <td><input type="text" name="totalServiceAmount" id="totalServiceAmount" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">合同总金额/元</td>
            <td><input type="text" name="totalContractAmount" id="totalContractAmount" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">不含税合同总金额/元</td>
            <td><input type="text" name="totalNonTaxAmount" id="totalNonTaxAmount" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">付款条款</td>
            <td><textarea name="paymentProvision" id="paymentProvision" rows="3" class="form-control input-sm w300"  disabled></textarea></td>
        </tr>
        <tr>
            <td class="tableleft">合同状态</td>
            <td>
                <select name="contractStatus" id="contractStatus" class="form-control input-sm w300"  disabled>
                </select>
            </td>
        </tr>
    </table>

    <p>验收信息：</p>
    <table class="table table-bordered table-hover m10">
        <tr>
            <td width="10%" class="tableleft">预计初验日期</td>
            <td><input type="text" name="expectedEarlyDate" id="expectedEarlyDate" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">实际初验日期</td>
            <td><input type="text" name="actualEarlyDate" id="actualEarlyDate" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">预计终验日期</td>
            <td><input type="text" name="expectedFinalDate" id="expectedFinalDate" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">实际终验日期</td>
            <td><input type="text" name="actualFinalDate" id="actualFinalDate" class="form-control input-sm w300" disabled/></td>
        </tr>
        <tr>
            <td class="tableleft">维保结束日期</td>
            <td><input type="text" name="maintenanceEndDate" id="maintenanceEndDate" class="form-control input-sm w300" disabled/></td>
        </tr>
    </table>
    <p>备注：</p>
    <table class="table table-bordered table-hover m10">
        <tr>
            <td width="10%" class="tableleft">备注</td>
            <td><textarea name="description" id="description" rows="3" class="form-control input-sm w300" disabled></textarea></td>
        </tr>
    </table>
</form>
<script type="text/javascript" src="../../libs/bootstrap-3.3.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="../../libs/bootstrap-datepicker/bootstrap-datepicker.min.css" />
<script type="text/javascript" src="../../libs/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script type="text/javascript" src="../../libs/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../js/validateform.js"></script>
<script type="text/javascript" src="../../js/formatTime.js"></script> <!--格式化时间 $.myTime.UnixToDate(unix)-->
<script type="text/javascript">
    $(function () {
        $('#backlist').click(function(){
            window.location.href="list.html"
        });
        $('#establishDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#singDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#expectedEarlyDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#actualEarlyDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#expectedFinalDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#actualFinalDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#maintenanceEndDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });

        getParamsByparamTypeValue('projectType', "#projectType");

        getParamsByparamTypeValue('saleType', "#saleType");

        getParamsByparamTypeValue('projectStatus', "#projectStatus");

        //加载部门下拉列表
        $.ajax({
            type: "POST",
            url: ctx + "/organization/getOrganization",
            success: function(data){
                if(data.code == 200){
                    SetdoubleOption('#pmOrganization', '#projectManager', data.data);
                    SetdoubleOption('#salerOrganization', '#saler', data.data);
                }
            }
        });

        $.ajax({
            type: "POST",
            url: ctx + "/user/queryByOraganizationId",
            data:{
                organizationId: 1
            },
            success: function(data){
                if(data.code == 200){
                    SetoptionUser('#saler', data.data.rows)
                }
            }
        });

        //关联项目
        $.ajax({
            type: "POST",
            url: ctx + "/project/query",
            success: function(data){
                if(data.code == 200){
                    SetProject('#relatedProject', data.data.rows)
                }
            }
        });
        function SetProject(id, param){
            var html = '';
            html +='<option value="">请选择</option>';
            for (var i =0;i<param.length;i++){
                html +='<option value="'+ param[i].projectId +'">'+ param[i].projectName +'</option>';
            }
            $(id).append(html);
        }

        getParamsByparamTypeValue('contractType', "#contractType");
        getParamsByparamTypeValue('contractStatus', "#contractStatus");

        // 提交
        $("#submitbtn").click(function () {
            if($("#subform").valid()){
                var formdata = $("#subform").serializeJson();
                $.ajax({
                    type: 'POST',
                    url: ctx + "/project/add",
                    contentType: "application/json",
                    dataType: 'json',
                    data: JSON.stringify(formdata),
                    success: function(data){
                        alert(data.msg)
                    }
                })
            }
        });

        //更新
        $("#updatebtn").click(function () {
            if($("#subform").valid()){
                var formdata = $("#subform").serializeJson()
                $.ajax({
                    type: 'POST',
                    url: ctx + "/project/update",
                    contentType: "application/json",
                    dataType: 'json',
                    data: JSON.stringify(formdata),
                    success: function(data){
                        alert(data.msg)
                    }
                })
            }
        });

        $("#submitbtn").hide();
        $("#updatebtn").show();
        var id = getQueryString('id');
        $.ajax({
            type: "POST",
            url: ctx + "/project/query",
            data:{
                projectId: id
            },
            success: function(data){
                if(data.code == 200){
                    var backData = data.data.rows[0];
                    backData.establishDate = $.myTime.UnixToDate(backData.establishDate);
                    backData.singDate = $.myTime.UnixToDate(backData.singDate);
                    backData.expectedEarlyDate = $.myTime.UnixToDate(backData.expectedEarlyDate);
                    backData.actualEarlyDate = $.myTime.UnixToDate(backData.actualEarlyDate);
                    backData.expectedFinalDate = $.myTime.UnixToDate(backData.expectedFinalDate);
                    backData.actualFinalDate = $.myTime.UnixToDate(backData.actualFinalDate);
                    backData.maintenanceEndDate = $.myTime.UnixToDate(backData.maintenanceEndDate);

                    var projectManager = backData.projectManager?backData.projectManager:1;
                    var saler = backData.saler?backData.saler:1;
                    $.ajax({
                        type: "POST",
                        url: ctx + "/organization/queryUserOrganization",
                        data:{
                            userId: projectManager
                        },
                        success: function(data){
                            if(data.code == 200){
                                backData.organization =data.data[0].organizationId;
                                $.ajax({
                                    type: "POST",
                                    url: ctx + "/user/queryByOraganizationId",
                                    data:{
                                        organizationId: backData.organization
                                    },
                                    success: function(data){
                                        if(data.code == 200){
                                            SetoptionUser('#projectManager', data.data.rows);
                                            $("#subform").setForm(backData);
                                            console.log(backData)
                                        }
                                    }
                                })
                            }
                        }
                    });

                    $.ajax({
                        type: "POST",
                        url: ctx + "/organization/queryUserOrganization",
                        data:{
                            userId: saler
                        },
                        success: function(data){
                            if(data.code == 200){
                                backData.organization =data.data[0].organizationId;
                                $.ajax({
                                    type: "POST",
                                    url: ctx + "/user/queryByOraganizationId",
                                    data:{
                                        organizationId: backData.organization
                                    },
                                    success: function(data){
                                        if(data.code == 200){
                                            SetoptionUser('#saler', data.data.rows);
                                            $("#subform").setForm(backData);
                                            console.log(backData)
                                        }
                                    }
                                })
                            }
                        }
                    });
                } else {
                    alert(data.msg)
                }
            }
        });

    });

    //联动
    function SetdoubleOption(orgElement, userElement, param){
        var html = '';
        html +='<option value="">请选择</option>';
        for (var i =0;i<param.length;i++){
            html +='<option value="'+ param[i].organizationId +'">'+ param[i].orgName +'</option>';
        }
        $(orgElement).append(html);
        var orgid = $(orgElement).val();
        $.ajax({
            type: "POST",
            url: ctx + "/user/queryByOraganizationId",
            data:{
                organizationId: orgid
            },
            success: function(data){
                if(data.code == 200){
                    SetoptionUser(userElement, data.data.rows)
                }
            }
        });
        //联动select
        $(orgElement).on("change",function(){
            orgid = $(orgElement).val()
            $.ajax({
                type: "POST",
                url: ctx + "/user/queryByOraganizationId",
                data:{
                    organizationId: orgid
                },
                success: function(data){
                    if(data.code == 200){
                        SetoptionUser(userElement, data.data.rows)
                    }
                }
            })
        });
    }

    function SetoptionUser(id, param){
        $(id).empty();
        var html = '';
        html +='<option value="">请选择</option>';
        for (var i =0;i<param.length;i++){
            html +='<option value="'+ param[i].userId +'">'+ param[i].userName +'</option>';
        }
        $(id).append(html);
    }
</script>
</body>
</html>